package com.harmonyos.service.impl;

import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.harmonyos.domain.TbTz;
import com.harmonyos.mapper.TbZiMapper;
import com.harmonyos.service.TbZiService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

/**
 *
 */
@Service
public class TbZiServiceImpl extends ServiceImpl<TbZiMapper, TbTz>
implements TbZiService {

    @Resource
    private TbZiMapper tbZiMapper;
    @Override
    public String insert(TbTz tz) {
        HashMap<String, Object> objectObjectHashMap = new HashMap<>();
        try {
            tbZiMapper.insert(tz);
            objectObjectHashMap.put("code","200");
        } catch (Exception e) {
            objectObjectHashMap.put("code","500");
            e.printStackTrace();
        }
        return JSONUtil.toJsonStr(objectObjectHashMap);
    }

    @Override
    public String delete(TbTz user) {
        QueryWrapper<TbTz> qu= new QueryWrapper<>();
        qu.eq("id",user.getId());
        HashMap<String, Object> objectObjectHashMap = new HashMap<>();
        try {
            tbZiMapper.delete(qu);
            objectObjectHashMap.put("code","200");
        } catch (Exception e) {
            objectObjectHashMap.put("code","500");
            e.printStackTrace();
        }
        return JSONUtil.toJsonStr(objectObjectHashMap);
    }

    @Override
    public List<TbTz> select(String user) {
        HashMap<String, Object> objectObjectHashMap = new HashMap<>();
        QueryWrapper<TbTz> qu= new QueryWrapper<>();
        qu.eq("byuser",user);
        List<TbTz> tbUser = tbZiMapper.selectList(qu);
        return tbUser;
    }

    @Override
    public String update(TbTz tbTz) {
        HashMap<String, Object> objectObjectHashMap = new HashMap<>();
        try {
            tbZiMapper.updateById(tbTz);
            objectObjectHashMap.put("code","200");
        } catch (Exception e) {
            objectObjectHashMap.put("code","500");
            e.printStackTrace();
        }
        return JSONUtil.toJsonStr(objectObjectHashMap);
    }


    @Override
    public List<TbTz> selectAll() {
        QueryWrapper<TbTz> qu= new QueryWrapper<>();
        return tbZiMapper.selectList(qu);
    }
}




